package com.ruoyi.dynamic.controller.app;


import com.ruoyi.common.core.constant.constant.PathConstant;
import com.ruoyi.common.core.context.SecurityContextHolder;
import com.ruoyi.common.core.pojo.result.Pages;
import com.ruoyi.common.core.pojo.vo.BaseVO;
import com.ruoyi.common.core.pojo.vo.PageVO;
import com.ruoyi.common.core.pojo.vo.SingleVO;
import com.ruoyi.common.core.result.Result;
import com.ruoyi.dynamic.model.pojo.request.app.*;
import com.ruoyi.dynamic.model.pojo.result.app.AppRoomVoteMusicResult;
import com.ruoyi.dynamic.service.IRoomVoteMusicService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Tag(name = "App-房间歌曲投票相关", description = "App-房间歌曲投票相关")
@RestController
@RequestMapping(PathConstant.APP_PATH + "vote-music")
public class AppVoteMusicController {

    @Autowired
    private IRoomVoteMusicService iRoomVoteMusicService;

    @Operation(summary = "发起投票/重新发起投票", description = "发起投票/重新发起投票")
    @PostMapping("create")
    public BaseVO create(@RequestBody @Validated AppRoomVoteMusicAddRequest request) {
        Long userId = SecurityContextHolder.getUserId();
        return Result.successOrFail(iRoomVoteMusicService.create(userId, request));
    }

    @Operation(summary = "修改模板", description = "修改模板")
    @PostMapping("updateTem")
    public BaseVO updateTem(@RequestBody @Validated AppRoomVoteMusicUpdateRequest request) {
        Long userId = SecurityContextHolder.getUserId();
        return Result.successOrFail(iRoomVoteMusicService.updateTem(userId, request));
    }

    @Operation(summary = "模板发起投票/重新发起投票", description = "模板发起投票/重新发起投票")
    @PostMapping("templateCreate")
    public BaseVO templateCreate(@RequestBody @Validated AppRoomVoteMusicTemRequest request) {
        Long userId = SecurityContextHolder.getUserId();
        return Result.successOrFail(iRoomVoteMusicService.templateCreate(userId, request));
    }

    @Operation(summary = "投票历史/投票模板", description = "投票历史/投票模板")
    @GetMapping("listPage")
    public PageVO<AppRoomVoteMusicResult> listPage(@ParameterObject AppRoomVoteSearchRequest request) {
        Pages<AppRoomVoteMusicResult> pages = iRoomVoteMusicService.listPage(request, SecurityContextHolder.getUserId());
        return Result.page(pages);
    }

    @Operation(summary = "投票详情", description = "投票详情")
    @GetMapping("info")
    public SingleVO<AppRoomVoteMusicResult> info(@Parameter(description = "投票id") Long id) {
        return Result.single(iRoomVoteMusicService.info(id, SecurityContextHolder.getUserId()));
    }

    @Operation(summary = "结束投票", description = "结束投票")
    @PostMapping("over")
    public BaseVO over(@RequestBody @Validated AppRoomVoteMusicOverRequest request) {
        boolean add = iRoomVoteMusicService.over(request, SecurityContextHolder.getUserId());
        return Result.successOrFail(add);
    }

    @Operation(summary = "立即投票", description = "立即投票")
    @PostMapping
    public BaseVO start(@RequestBody @Validated AppRoomVoteMusicStartRequest request) {
        boolean add = iRoomVoteMusicService.start(request, SecurityContextHolder.getUserId());
        return Result.successOrFail(add);
    }

    @Operation(summary = "投票历史-存模板", description = "投票历史-存模板")
    @GetMapping("save-tem")
    public BaseVO saveTem(@Parameter(description = "投票历史id") Long id) {
        return Result.successOrFail(iRoomVoteMusicService.saveTem(id, SecurityContextHolder.getUserId()));
    }


    @Operation(summary = "取消投票模板", description = "取消投票模板")
    @GetMapping("removeTem")
    public BaseVO removeTem(@Parameter(description = "投票模板id") Long id) {
        return Result.successOrFail(iRoomVoteMusicService.removeTem(id));
    }


}

